package com.vitabuybuy.tv.ui.mine.order.after

import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityNegotiationHistoryBinding
import com.library.common.base.BaseActivity
import com.vitabuybuy.tv.ui.mine.order.after.adapter.NegotiationHistoryAdapter
import com.vitabuybuy.tv.ui.mine.order.after.viewmodel.AfterSaleViewModel

class NegotiationHistoryActivity : BaseActivity<AfterSaleViewModel, ActivityNegotiationHistoryBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_negotiation_history

    private var orderId: Int? = 0
    private val mAdapter by lazy { NegotiationHistoryAdapter() }

    override fun onGetBundle(bundle: Bundle?) {
        orderId = bundle?.getInt("orderId")
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle("协商历史")
        mBinding.mViewModel = viewModel
        mBinding.listview.run {
            adapter = mAdapter
            layoutManager = LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)
        }
    }

    override fun observeData() {
        viewModel.getNegotiationList(orderId)
        viewModel.negotiationList.observe(this, Observer {
            mAdapter.setNewData(it)
        })
    }

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, orderId: Int?) {
            mContext.startActivity(
                bundleOf(Pair("orderId", orderId)),
                NegotiationHistoryActivity::class.java
            )
        }
    }
}
